package com.yaolisheng.poetryandode.config;

/**
 * @Author yls
 * @Date 2021/6/4 15:46
 * @Version 1.0
 */
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@EnableCaching
public class UserLoginAdapter implements WebMvcConfigurer {

    @Autowired
    private UserLoginInterceptor userLoginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //添加对用户是否登录的拦截器，并添加过滤项、排除项
        registry.addInterceptor(userLoginInterceptor).addPathPatterns("/**")
                //排除样式、脚本、图片等资源文件
                .excludePathPatterns("/css/**","/js/**","/images/**")
                //排除登录按钮
                .excludePathPatterns("/login")
                //提交注册请求
                .excludePathPatterns("/register")
                //转到注册页面
                .excludePathPatterns("/toRegister")
                //转到登录页面
                .excludePathPatterns("/");

    }

}